package org.beetl.sql.core.db;

import java.lang.annotation.Annotation;
import java.util.List;

import org.beetl.sql.annotation.entity.AssignID;
import org.beetl.sql.annotation.entity.AutoID;
import org.beetl.sql.annotation.entity.SeqID;
import org.beetl.sql.clazz.kit.BeanKit;
import org.beetl.sql.core.ConnectionSource;
import org.beetl.sql.core.meta.MetadataManager;

public class LegacySqlServer2012Style extends SqlServer2012Style{
	private boolean fetchRemark = true;
	
	public LegacySqlServer2012Style() {
		super();
	}

	public LegacySqlServer2012Style(boolean fetchRemark) {
		super(fetchRemark);
		this.fetchRemark = fetchRemark;
	}

	@Override
	public int getIdType(Class c, String idProperty) {
		List<Annotation> ans = BeanKit.getAllAnnotation(c, idProperty);
		//默认是自增长
		int idType = DBType.ID_AUTO;

		for (Annotation an : ans) {
			if (an instanceof AutoID) {
				idType = DBType.ID_AUTO;
				break;
			} else if (an instanceof SeqID) {
				idType = DBType.ID_SEQ;
				break;
			} else if (an instanceof AssignID) {
				idType = DBType.ID_ASSIGN;
				break;
			} else if(an instanceof org.beetl.sql.core.annotatoin.AssignID) {
				idType = DBType.ID_ASSIGN;
			} else if(an instanceof org.beetl.sql.core.annotatoin.SeqID) {
				idType = DBType.ID_SEQ;
				break;
			} else if(an instanceof org.beetl.sql.core.annotatoin.AutoID) {
				idType = DBType.ID_AUTO;
				break;
			}
		}

		return idType;
	}
	
	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs) {
		metadataManager = new LegacyMSSqlServerMetadataManager(cs, this,fetchRemark);
		return metadataManager;
	}

	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs, String defaultSchema, String defalutCatalog) {
		metadataManager = new LegacyMSSqlServerMetadataManager(cs, defaultSchema, defalutCatalog, this,fetchRemark);
		return metadataManager;
	}

}
